let App = getApp();

Page({
  data: {
    list: [],
    default_id: null,
  },

  onLoad: function(options) {
    // 当前页面参数
    this.data.options = options;
  },

  onShow: function() {
    // 获取收货地址列表
    //this.getAddressList();

    // 获取我的商店
    this.getMyShop();
  },

  /**
   * 获取我的商店
   */
  getMyShop: function() {
    let _this = this;
    App._get('shop/myShop', {}, function(result) {
      let myShop = result.data.list;
      if (myShop) {
        for (var j = 0; j < myShop.length; j++) {
          myShop[j]['images'] = App.root + myShop[j]['images'];
        }
      }
      _this.setData({
        list: myShop
      });
    });
  },

  /**
   * 新增商店申请
   */
  createShop: function() {
    wx.navigateTo({
      url: './addshop'
    });
  },

  /**
   * 编辑商店
   */
  editShop: function(e) {
    wx.navigateTo({
      url: "./editshop?shop_id=" + e.currentTarget.dataset.shop_id
    });
  },

  /**
   * 移除收货地址
   */
  removeShop: function(e) {
    let _this = this,
      shop_id = e.currentTarget.dataset.shop_id;
    wx.showModal({
      title: "提示",
      content: "您确定要移除当前商店吗?",
      success: function(o) {
        o.confirm && App._post_form('shop/delete', {
          shop_id
        }, function(result) {
          _this.getMyShop();
        });
      }
    });
  },

  

});